package yl.hs.bmipfull.controllers.chart;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.daos.material.IPurchaseContractProductDao;
import yl.hs.bmipfull.daos.material.IPurchaseReceiptDao;
import yl.hs.bmipfull.pojo.laboratory.ProductInfoEntity;
import yl.hs.bmipfull.pojo.material.PurchaseContractProductEntity;
import yl.hs.bmipfull.pojo.material.PurchaseReceiptEntity;
import yl.hs.bmipfull.pojo.production.*;
import yl.hs.bmipfull.service.laboratory.IProductCateService;
import yl.hs.bmipfull.service.laboratory.IProductInfoService;
import yl.hs.bmipfull.service.material.IPurchaseContractProductService;
import yl.hs.bmipfull.service.production.*;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.WebResult;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 作用:   <br/>
 * 创建时间: 2023-07-25 10:14 <br/>
 *
 * @author 吴高丰
 */
@Api(value = "图表中心-生产web接口", tags = "图表中心-财务")
@RestController
@RequestMapping(value = "/api/HFCahar")
public class HFCaharContoller extends ControllerBase {
    @Autowired
    IProductionTaskFertilizerService taskFertilizerService;
    @Autowired
    IBrickShipService shipService;
    @Autowired
    IFinishProductInventoryService finishProductInventoryService;
    @Autowired
    IProductInfoService infoService;
    @Autowired
    IProductCateService cateService;
    @Autowired
    IBrickShipService brickShipService;
    @Autowired
    IPurchaseReceiptDao receiptDao;
    @Autowired
    IProductionConsumeService consumeService;
    @Autowired
    IPurchaseContractProductService purchaseContractProductService;
    @Autowired
    IFinishProductWarehouseRecordService warehouseRecordService;

    @ApiOperation(value = "生产中的生产任务", notes = "生产中的生产任务")
    @RequestMapping(value = "/productTask", method = RequestMethod.GET)
    public WebResult getProductTask() {
        try {
            PageQuery page = new PageQuery();
            page.getQuery().put("state", 3);
            var result = taskFertilizerService.queryPage(page, 999999, 1);
            return success("查询成功", result.getData());
        } catch (Exception e) {
            return error(e.toString());
        }
    }

    @ApiOperation(value = "生产中的生产任务", notes = "生产中的生产任务")
    @RequestMapping(value = "/productTaskQuantity", method = RequestMethod.GET)
    public WebResult getProductTaskQuantity() {
        try {
            PageQuery page = new PageQuery();
            page.getQuery().put("state", 3);
            var result = taskFertilizerService.queryPage(page, 999999, 1);
            var quantity = BigDecimal.valueOf(0);
            for (Object datum : result.getData()) {
                var ss = (Map<String, Object>) datum;
                var yl = (BigDecimal) ss.get("syquantity");
                quantity = quantity.add(yl);
            }
            return success("查询成功", quantity);
        } catch (Exception e) {
            return error(e.toString());
        }
    }

    @ApiOperation(value = "品牌成品库存", notes = "品牌成品库存")
    @RequestMapping(value = "/FinishProductInventory", method = RequestMethod.GET)
    public WebResult getFinishProductInventory() {
        try {
            var results = finishProductInventoryService.queryBrandInventory();
            Map<String, Object> result = new HashMap<>();
            List<String> data = new ArrayList<>();
            List<Object> data1 = new ArrayList<>();
            List<Object> data2 = new ArrayList<>();
            results.forEach(d -> {
                data.add(d.getCateName());
                data1.add(d.getWeight());
                data2.add(d.getQuantity());
            });
            result.put("cate", data);
            result.put("weight", data1);
            result.put("quantity", data2);
            return success("查询成功", result);
        } catch (Exception e) {
            return error(e.toString());
        }
    }

    @ApiOperation(value = "品牌发货量统计", notes = "品牌发货量统计")
    @RequestMapping(value = {"/getHFShipOrder/{state}", "/getHFShipOrder/{state}/{productCateSN}"}, method = RequestMethod.GET)
    public WebResult getHFShipOrder(@PathVariable int state, @PathVariable(required = false) String productCateSN) {
        var startTime = "";
        var endTime = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();// 获取当前日期
        if (state == 0) {
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        } else {
            calendar.add(Calendar.YEAR, 0);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();// 获取当前日期
            calendars.add(Calendar.YEAR, 0);
            calendars.add(Calendar.MONTH, 0);
            calendars.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// 获取当前月最后一天
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        }
        Map<String, Object> result = new HashMap<>();
        List<String> cate = new ArrayList<>();
        List<Object> quantity = new ArrayList<>();
        List<Object> weight = new ArrayList<>();
        PageQuery page = new PageQuery();
        page.getQuery().put("startTime", startTime);
        page.getQuery().put("endTime", endTime);
        if (productCateSN != null) {
            page.getQuery().put("productCateSN", productCateSN);
            var shiporder = brickShipService.queryList(page);
            var map = shiporder.stream().collect(Collectors.groupingBy(BrickShipOrderModel::getProductName));
            List<BrickShipOrderModel> model = new ArrayList<>();
            map.keySet().forEach(s -> {
                BrickShipOrderModel entity = new BrickShipOrderModel();
                entity.setProductCate(s);
                var ship = map.get(s).stream().filter(d -> d.getProductName().equals(s)).toList();
                var weights = ship.stream().map(BrickShipOrderModel::getQuantity).reduce(BigDecimal::add);
                var quantitys = ship.stream().map(BrickShipOrderModel::getVolume).reduce(BigDecimal::add);
                entity.setQuantity(quantitys.isPresent() == false ? BigDecimal.valueOf(0) : quantitys.get().setScale(2, RoundingMode.DOWN));
                entity.setVolume(weights.isPresent() == false ? BigDecimal.valueOf(0) : weights.get().setScale(2, RoundingMode.DOWN));
                model.add(entity);
            });
            var datass = model.stream().sorted(Comparator.comparing(BrickShipOrderModel::getQuantity).reversed()).toList();
            datass.forEach(s -> {
                cate.add(s.getProductCate());
                quantity.add(s.getQuantity());
                weight.add(s.getVolume());
            });
        } else {
            var shiporder = brickShipService.queryList(page);
            var map = shiporder.stream().collect(Collectors.groupingBy(BrickShipOrderModel::getProductCate));
            List<BrickShipOrderModel> model = new ArrayList<>();
            map.keySet().forEach(s -> {
                BrickShipOrderModel entity = new BrickShipOrderModel();
                entity.setProductCate(s);
                //cate.add(s);
                var ship = map.get(s).stream().filter(d -> d.getProductCate().equals(s)).toList();
                var weights = ship.stream().map(BrickShipOrderModel::getQuantity).reduce(BigDecimal::add);
                var quantitys = ship.stream().map(BrickShipOrderModel::getVolume).reduce(BigDecimal::add);
                //weight.add(weights.isPresent()==false?0:weights.get().setScale(2, RoundingMode.DOWN));
                //quantity.add(quantitys.isPresent()==false?0:quantitys.get().setScale(2, RoundingMode.DOWN));
                entity.setQuantity(quantitys.isPresent() == false ? BigDecimal.valueOf(0) : quantitys.get().setScale(2, RoundingMode.DOWN));
                entity.setVolume(weights.isPresent() == false ? BigDecimal.valueOf(0) : weights.get().setScale(2, RoundingMode.DOWN));
                model.add(entity);
            });
            var datass = model.stream().sorted(Comparator.comparing(BrickShipOrderModel::getQuantity).reversed()).toList();
            datass.forEach(s -> {
                cate.add(s.getProductCate());
                quantity.add(s.getQuantity());
                weight.add(s.getVolume());
            });

        }
        result.put("cate", cate);
        result.put("quantity", quantity);
        result.put("weight", weight);
        return success("查询成功", result);
    }

    @ApiOperation(value = "销售额", notes = "销售额")
    @RequestMapping(value = {"/getHFShipOrderMoney/{state}", "/getHFShipOrderMoney/{state}/{productCateSN}"}, method = RequestMethod.GET)
    public WebResult getHFShipOrderMoney(@PathVariable int state, @PathVariable(required = false) String productCateSN) {
        var startTime = "";
        var endTime = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (state == 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        } else {
            Calendar calendar = Calendar.getInstance();// 获取当前日期
            calendar.add(Calendar.YEAR, 0);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();// 获取当前日期
            calendars.add(Calendar.YEAR, 0);
            calendars.add(Calendar.MONTH, 0);
            calendars.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// 获取当前月最后一天
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        }
        Map<String, Object> result = new HashMap<>();
        List<String> cate = new ArrayList<>();
        List<Object> quantity = new ArrayList<>();
        List<Object> weight = new ArrayList<>();
        PageQuery page = new PageQuery();
        page.getQuery().put("startTime", startTime);
        page.getQuery().put("endTime", endTime);
        var money = new BigDecimal(0);
        if (productCateSN != null) {
            page.getQuery().put("productCateSN", productCateSN);
            var shiporder = brickShipService.queryList(page);
            for (BrickShipOrderModel brickShipOrderModel : shiporder) {
                money = money.add(brickShipOrderModel.getQuantity().multiply(brickShipOrderModel.getShipmentReviewPrice()));
            }
        } else {
            var shiporder = brickShipService.queryList(page);
            for (BrickShipOrderModel brickShipOrderModel : shiporder) {
                money = money.add(brickShipOrderModel.getQuantity().multiply(brickShipOrderModel.getShipmentReviewPrice()));
            }
        }
        return success("查询成功", money.divide(BigDecimal.valueOf(10000)).setScale(2, RoundingMode.HALF_UP));
    }

    @ApiOperation(value = "原材入库量", notes = "原材入库量")
    @RequestMapping(value = "/getycliang/{state}", method = RequestMethod.GET)
    public WebResult getRm(@PathVariable int state) {
        var startTime = "";
        var endTime = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (state == 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        } else {
            Calendar calendar = Calendar.getInstance();// 获取当前日期
            calendar.add(Calendar.YEAR, 0);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();// 获取当前日期
            calendars.add(Calendar.YEAR, 0);
            calendars.add(Calendar.MONTH, 0);
            calendars.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// 获取当前月最后一天
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        }
        Map<String, Object> result = new HashMap<>();
        List<String> cate = new ArrayList<>();
        List<Object> weight = new ArrayList<>();
        PageQuery page = new PageQuery();
        page.getQuery().put("startTime", startTime);
        page.getQuery().put("endTime", endTime);
        var shiporder = receiptDao.queryList(page.getQuery(), null, null);
        var map = shiporder.stream().collect(Collectors.groupingBy(PurchaseReceiptEntity::getRmSN));
        List<PurchaseReceiptEntity> datas = new ArrayList<>();
        map.keySet().forEach(s -> {
            PurchaseReceiptEntity entity = new PurchaseReceiptEntity();
            var purchase = map.get(s);
            //cate.add(purchase.get(0).getRmCate()+"-"+purchase.get(0).getRmName()+"-"+purchase.get(0).getRmSpec());
            var ship = map.get(s).stream().filter(d -> d.getRmSN().equals(s)).toList();
            var weights = ship.stream().map(PurchaseReceiptEntity::getNetWeight).reduce(BigDecimal::add);
            //weight.add(weights.isPresent()==false?0:weights.get().setScale(2, RoundingMode.DOWN));
            entity.setRmName(purchase.get(0).getRmCate() + "-" + purchase.get(0).getRmName() + "-" + purchase.get(0).getRmSpec());
            entity.setNetWeight(weights.isPresent() == false ? BigDecimal.valueOf(0) : weights.get().setScale(2, RoundingMode.DOWN));
            datas.add(entity);
        });
        var datass = datas.stream().sorted(Comparator.comparing(PurchaseReceiptEntity::getNetWeight).reversed()).toList();
        datass.forEach(s -> {
            cate.add(s.getRmName());
            weight.add(s.getNetWeight());
        });
        result.put("xAxis", cate);
        result.put("data", weight);
        return success("查询成功", result);
    }

    @ApiOperation(value = "具体产品成品库存", notes = "具体产品成品库存")
    @RequestMapping(value = "/FinishProductInventory/{cateSN}", method = RequestMethod.GET)
    public WebResult getFinishProductInventory(@PathVariable String cateSN) {
        try {
            var results = finishProductInventoryService.queryBrandByCateName(cateSN);
            Map<String, Object> result = new HashMap<>();
            List<String> data = new ArrayList<>();
            List<Object> data1 = new ArrayList<>();
            List<Object> data2 = new ArrayList<>();
            results.forEach(d -> {
                data.add(d.getProductName());
                data1.add(d.getWeight());
                data2.add(d.getQuantity());
            });
            result.put("cate", data);
            result.put("weight", data1);
            result.put("quantity", data2);
            return success("查询成功", result);
        } catch (Exception e) {
            return error(e.toString());
        }
    }

    @ApiOperation(value = "获取天然气电量当天消耗量", notes = "获取天然气电量当天消耗量")
    @RequestMapping(value = "/getConsome/{state}/{type}", method = RequestMethod.GET)
    public WebResult getConsome(@PathVariable int state, @PathVariable String type) {
        var startTime = "";
        var endTime = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (state == 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        } else {
            Calendar calendar = Calendar.getInstance();// 获取当前日期
            calendar.add(Calendar.YEAR, 0);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();// 获取当前日期
            calendars.add(Calendar.YEAR, 0);
            calendars.add(Calendar.MONTH, 0);
            calendars.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// 获取当前月最后一天
            calendars.set(Calendar.HOUR_OF_DAY, 23);
            calendars.set(Calendar.MINUTE, 59);
            calendars.set(Calendar.SECOND, 59);
            calendars.set(Calendar.MILLISECOND, 999);
            endTime = sdf.format(calendars.getTime());
        }
        PageQuery page = new PageQuery();
        page.getQuery().put("startTime", startTime);
        page.getQuery().put("endTime", endTime);
        page.getQuery().put("name", type);
        try {
            var list = consumeService.queryList(page).stream().map(ProductionConsumeEntity::getQuantity).reduce(BigDecimal::add);
            if (list.isPresent()) {
                return success("查询成功", list);
            } else {
                return success("查询成功", 0);
            }
        } catch (Exception e) {
            return error(e);
        }
    }

    //data:{
    //data:[[1,0,1]],
    //legend:['电费'],
    //xAxis:[2023-08-21,2023-08-22,2023-08-23]
    //}
    @ApiOperation(value = "获取近30天天然气电量当天消耗量", notes = "获取近30天天然气电量当天消耗量")
    @RequestMapping(value = "/queryConsumMonth/{name}", method = RequestMethod.GET)
    public WebResult queryConsumMonth(@PathVariable String name) {
        var list = consumeService.quantityBYMonth(name);
        Map<String, Object> map = new HashMap<>();
        List<Object> data = new ArrayList<>();
        List<Object> datas = new ArrayList<>();
        List<Object> legend = new ArrayList<>();
        List<Object> xAxis = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        for (ProductionConsumeEntity item : list) {
            data.add(item.getQuantity());
            String formattedTime = format.format(item.getAddtime());
            xAxis.add(formattedTime);
        }
        datas.add(data);
        legend.add(name);
        map.put("data", datas);
        map.put("legend", legend);
        map.put("xAxis", xAxis);
        return success("查询成功", map);
    }

    @ApiOperation(value = "查询原材供应余量", notes = "查询原材供应余量")
    @RequestMapping(value = "/queryRmDaiRu", method = RequestMethod.GET)
    public WebResult queryRmDaiRu() {
        var result = purchaseContractProductService.quantityGroupByRmSn();
        List<Object> data = new ArrayList<>();
        List<Object> xAxis = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        for (Map<String, Object> item : result) {
            data.add(item.get("margin"));
            xAxis.add(item.get("RmCateName").toString() + "-" + item.get("rmName").toString() + "-" + item.get("rmSpec").toString());
        }
        map.put("data", data);
        map.put("xAxis", xAxis);
        return success("查询成功", map);
    }

    @ApiOperation(value = "查询昨天入库量", notes = "查询昨天入库量")
    @RequestMapping(value = "/productRk/{plineSn}", method = RequestMethod.GET)
    public WebResult productRk(@PathVariable String plineSn) {
        try {
            var startTime = "";
            var endTime = "";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            endTime = sdf.format(calendar.getTime());
            Calendar calendars = Calendar.getInstance();
            calendars.set(Calendar.SECOND, 0);
            calendars.set(Calendar.MINUTE, 0);
            calendars.set(Calendar.HOUR_OF_DAY, 0);
            calendars.set(Calendar.MILLISECOND, 0);
            calendars.add(Calendar.DAY_OF_MONTH, -1);
            startTime = sdf.format(calendars.getTime());
            PageQuery page = new PageQuery();
            page.getQuery().put("startTime", startTime);
            page.getQuery().put("endTime", endTime);
            page.getQuery().put("type", 0);
            List<Object> data = new ArrayList<>();
            var result = warehouseRecordService.queryList(page).stream().collect(Collectors.groupingBy(FinishProductWarehouseRecordEntity::getTaskSN));
            var quantity = new BigDecimal(0);
            for (String s : result.keySet()) {
                var task = taskFertilizerService.findBySn(s);
                if (task != null) {
                    if (task.getPlineSn().equals(plineSn)) {
                        var ss = result.get(s).stream().map(FinishProductWarehouseRecordEntity::getWeight).reduce(BigDecimal::add);
                        quantity = quantity.add(ss.isPresent() ? ss.get() : BigDecimal.valueOf(0));
                    }
                }
            }
            return success("查询成功", quantity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return success("查询成功");
    }
}
